package com.sunshine.rest;

import org.restlet.data.MediaType;
import org.restlet.ext.jackson.JacksonRepresentation;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author WeiHong
 * @date 2018/11/15
 */
public class RestClient {
    public static void main(String[] args) throws IOException {

        ClientResource client = new ClientResource("http://localhost:8081/findPerson/1");
        // 调用get方法，服务器发布的是GET
        Representation response = client.get(MediaType.APPLICATION_JSON);
        // 创建JacksonRepresentation实例，将响应转换为Map
        JacksonRepresentation jr = new JacksonRepresentation(response, HashMap.class);
        // 获取转换后的Map对象
        Map result = (HashMap) jr.getObject();
        // 输出结果
        System.out.println(result.get("id") + "-" + result.get("name") + "-"
                + result.get("age") + "-" + result.get("message"));
    }
}
